﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Data.SqlClient;

/// <summary>
/// 缴费人员表dao 的摘要说明
/// </summary>
public class 缴费人员表dao
{
	public 缴费人员表dao()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}

    #region  成员方法

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string personId)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from 缴费人员表");
			strSql.Append(" where personId=@personId ");
			SqlParameter[] parameters = {
					new SqlParameter("@personId", SqlDbType.NVarChar,50)};
			parameters[0].Value = personId;

			return DataBase.runExecuteScalar(strSql.ToString(), parameters) >= 1;
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(缴费人员表 model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into 缴费人员表(");
			strSql.Append("personId,insuranceId,username,sex,csrq,mz,whcd,ygxs,grsf,hkxz,gsdw,yzbm,phone,hkdz,txdz,cbzt,del)");
			strSql.Append(" values (");
			strSql.Append("@personId,@insuranceId,@username,@sex,@csrq,@mz,@whcd,@ygxs,@grsf,@hkxz,@gsdw,@yzbm,@phone,@hkdz,@txdz,@cbzt,@del)");
			SqlParameter[] parameters = {
					new SqlParameter("@personId", SqlDbType.NVarChar,18),
					new SqlParameter("@insuranceId", SqlDbType.NVarChar,50),
					new SqlParameter("@username", SqlDbType.NVarChar,50),
					new SqlParameter("@sex", SqlDbType.NVarChar,4),
					new SqlParameter("@csrq", SqlDbType.DateTime),
					new SqlParameter("@mz", SqlDbType.NVarChar,50),
					new SqlParameter("@whcd", SqlDbType.NVarChar,50),
					new SqlParameter("@ygxs", SqlDbType.NVarChar,50),
					new SqlParameter("@grsf", SqlDbType.NVarChar,50),
					new SqlParameter("@hkxz", SqlDbType.NVarChar,50),
					new SqlParameter("@gsdw", SqlDbType.NVarChar,50),
					new SqlParameter("@yzbm", SqlDbType.NVarChar,10),
					new SqlParameter("@phone", SqlDbType.NVarChar,20),
					new SqlParameter("@hkdz", SqlDbType.NVarChar,255),
					new SqlParameter("@txdz", SqlDbType.NVarChar,255),
					new SqlParameter("@cbzt", SqlDbType.NVarChar,10),
					new SqlParameter("@del", SqlDbType.Int,4)};
			parameters[0].Value = model.personId;
			parameters[1].Value = model.insuranceId;
			parameters[2].Value = model.username;
			parameters[3].Value = model.sex;
			parameters[4].Value = model.csrq;
			parameters[5].Value = model.mz;
			parameters[6].Value = model.whcd;
			parameters[7].Value = model.ygxs;
			parameters[8].Value = model.grsf;
			parameters[9].Value = model.hkxz;
			parameters[10].Value = model.gsdw;
			parameters[11].Value = model.yzbm;
			parameters[12].Value = model.phone;
			parameters[13].Value = model.hkdz;
			parameters[14].Value = model.txdz;
			parameters[15].Value = model.cbzt;
			parameters[16].Value = model.del;

            return DataBase.runExecute(strSql.ToString(), parameters);
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public int Update(缴费人员表 model) 
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update 缴费人员表 set ");
			strSql.Append("insuranceId=@insuranceId,");
			strSql.Append("username=@username,");
			strSql.Append("sex=@sex,");
			strSql.Append("csrq=@csrq,");
			strSql.Append("mz=@mz,");
			strSql.Append("whcd=@whcd,");
			strSql.Append("ygxs=@ygxs,");
			strSql.Append("grsf=@grsf,");
			strSql.Append("hkxz=@hkxz,");
			strSql.Append("gsdw=@gsdw,");
			strSql.Append("yzbm=@yzbm,");
			strSql.Append("phone=@phone,");
			strSql.Append("hkdz=@hkdz,");
			strSql.Append("txdz=@txdz,");
			strSql.Append("cbzt=@cbzt,");
			strSql.Append("del=@del");
			strSql.Append(" where personId=@personId ");
			SqlParameter[] parameters = {
					new SqlParameter("@personId", SqlDbType.NVarChar,18),
					new SqlParameter("@insuranceId", SqlDbType.NVarChar,50),
					new SqlParameter("@username", SqlDbType.NVarChar,50),
					new SqlParameter("@sex", SqlDbType.NVarChar,4),
					new SqlParameter("@csrq", SqlDbType.DateTime),
					new SqlParameter("@mz", SqlDbType.NVarChar,50),
					new SqlParameter("@whcd", SqlDbType.NVarChar,50),
					new SqlParameter("@ygxs", SqlDbType.NVarChar,50),
					new SqlParameter("@grsf", SqlDbType.NVarChar,50),
					new SqlParameter("@hkxz", SqlDbType.NVarChar,50),
					new SqlParameter("@gsdw", SqlDbType.NVarChar,50),
					new SqlParameter("@yzbm", SqlDbType.NVarChar,10),
					new SqlParameter("@phone", SqlDbType.NVarChar,20),
					new SqlParameter("@hkdz", SqlDbType.NVarChar,255),
					new SqlParameter("@txdz", SqlDbType.NVarChar,255),
					new SqlParameter("@cbzt", SqlDbType.NVarChar,10),
					new SqlParameter("@del", SqlDbType.Int,4)};
			parameters[0].Value = model.personId;
			parameters[1].Value = model.insuranceId;
			parameters[2].Value = model.username;
			parameters[3].Value = model.sex;
			parameters[4].Value = model.csrq;
			parameters[5].Value = model.mz;
			parameters[6].Value = model.whcd;
			parameters[7].Value = model.ygxs;
			parameters[8].Value = model.grsf;
			parameters[9].Value = model.hkxz;
			parameters[10].Value = model.gsdw;
			parameters[11].Value = model.yzbm;
			parameters[12].Value = model.phone;
			parameters[13].Value = model.hkdz;
			parameters[14].Value = model.txdz;
			parameters[15].Value = model.cbzt;
			parameters[16].Value = model.del;

            return DataBase.runExecute(strSql.ToString(), parameters);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public int Delete(string personId)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from 缴费人员表 ");
			strSql.Append(" where personId=@personId ");
			SqlParameter[] parameters = {
					new SqlParameter("@personId", SqlDbType.NVarChar,50)};
			parameters[0].Value = personId;

            return DataBase.runExecute(strSql.ToString(), parameters);
		}


		/// <summary>
		/// 得到一个对象实体，通过身份证号
		/// </summary>
		public 缴费人员表 GetModel(string personId)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 personId,insuranceId,username,sex,csrq,mz,whcd,ygxs,grsf,hkxz,gsdw,yzbm,phone,hkdz,txdz,cbzt,del from 缴费人员表 ");
			strSql.Append(" where personId=@personId ");
			SqlParameter[] parameters = {
					new SqlParameter("@personId", SqlDbType.NVarChar,50)};
			parameters[0].Value = personId;

			缴费人员表 model=new 缴费人员表();
			DataSet ds = DataBase.runProcGetSet(strSql.ToString(), parameters);
;
			if(ds.Tables[0].Rows.Count>0)
			{
				model.personId=ds.Tables[0].Rows[0]["personId"].ToString();
				model.insuranceId=ds.Tables[0].Rows[0]["insuranceId"].ToString();
				model.username=ds.Tables[0].Rows[0]["username"].ToString();
				model.sex=ds.Tables[0].Rows[0]["sex"].ToString();
				if(ds.Tables[0].Rows[0]["csrq"].ToString()!="")
				{
					model.csrq=DateTime.Parse(ds.Tables[0].Rows[0]["csrq"].ToString());
				}
				model.mz=ds.Tables[0].Rows[0]["mz"].ToString();
				model.whcd=ds.Tables[0].Rows[0]["whcd"].ToString();
				model.ygxs=ds.Tables[0].Rows[0]["ygxs"].ToString();
				model.grsf=ds.Tables[0].Rows[0]["grsf"].ToString();
				model.hkxz=ds.Tables[0].Rows[0]["hkxz"].ToString();
				model.gsdw=ds.Tables[0].Rows[0]["gsdw"].ToString();
				model.yzbm=ds.Tables[0].Rows[0]["yzbm"].ToString();
				model.phone=ds.Tables[0].Rows[0]["phone"].ToString();
				model.hkdz=ds.Tables[0].Rows[0]["hkdz"].ToString();
				model.txdz=ds.Tables[0].Rows[0]["txdz"].ToString();
				model.cbzt=ds.Tables[0].Rows[0]["cbzt"].ToString();
				if(ds.Tables[0].Rows[0]["del"].ToString()!="")
				{
					model.del=int.Parse(ds.Tables[0].Rows[0]["del"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

        /// <summary>
        /// 得到一个对象实体，通过个人编号
        /// </summary>
        public 缴费人员表 GetModelByInsuranceId(string insuranceId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 personId,insuranceId,username,sex,csrq,mz,whcd,ygxs,grsf,hkxz,gsdw,yzbm,phone,hkdz,txdz,cbzt,del from 缴费人员表 ");
            strSql.Append(" where insuranceId=@insuranceId ");
            SqlParameter[] parameters = {
					new SqlParameter("@insuranceId", SqlDbType.NVarChar,50)};
            parameters[0].Value = insuranceId;

            缴费人员表 model = new 缴费人员表();
            DataSet ds = DataBase.runProcGetSet(strSql.ToString(), parameters);
            ;
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.personId = ds.Tables[0].Rows[0]["personId"].ToString();
                model.insuranceId = ds.Tables[0].Rows[0]["insuranceId"].ToString();
                model.username = ds.Tables[0].Rows[0]["username"].ToString();
                model.sex = ds.Tables[0].Rows[0]["sex"].ToString();
                if (ds.Tables[0].Rows[0]["csrq"].ToString() != "")
                {
                    model.csrq = DateTime.Parse(ds.Tables[0].Rows[0]["csrq"].ToString());
                }
                model.mz = ds.Tables[0].Rows[0]["mz"].ToString();
                model.whcd = ds.Tables[0].Rows[0]["whcd"].ToString();
                model.ygxs = ds.Tables[0].Rows[0]["ygxs"].ToString();
                model.grsf = ds.Tables[0].Rows[0]["grsf"].ToString();
                model.hkxz = ds.Tables[0].Rows[0]["hkxz"].ToString();
                model.gsdw = ds.Tables[0].Rows[0]["gsdw"].ToString();
                model.yzbm = ds.Tables[0].Rows[0]["yzbm"].ToString();
                model.phone = ds.Tables[0].Rows[0]["phone"].ToString();
                model.hkdz = ds.Tables[0].Rows[0]["hkdz"].ToString();
                model.txdz = ds.Tables[0].Rows[0]["txdz"].ToString();
                model.cbzt = ds.Tables[0].Rows[0]["cbzt"].ToString();
                if (ds.Tables[0].Rows[0]["del"].ToString() != "")
                {
                    model.del = int.Parse(ds.Tables[0].Rows[0]["del"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select personId,insuranceId,username,sex,csrq,mz,whcd,ygxs,grsf,hkxz,gsdw,yzbm,phone,hkdz,txdz,cbzt,del ");
			strSql.Append(" FROM 缴费人员表 ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
            return DataBase.runProcGetSet(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" personId,insuranceId,username,sex,csrq,mz,whcd,ygxs,grsf,hkxz,gsdw,yzbm,phone,hkdz,txdz,cbzt,del ");
			strSql.Append(" FROM 缴费人员表 ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
            return DataBase.runProcGetSet(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "缴费人员表";
			parameters[1].Value = "ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  成员方法
}
